package com.xiaotu.server.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.xiaotu.common.model.SpiderLogModel;
import com.xiaotu.common.util.KeyLocker;

@Service
public class SpiderSystemService extends BaseService
{
	
	public void saveSpiderSystemLog(final SpiderLogModel spiderLog)
	{
		String seriesNo = spiderLog.getSeriesNo();
		if (StringUtils.isEmpty(seriesNo))
			throw new RuntimeException("seriesNo is empty!");
		KeyLocker.lock(seriesNo, new Runnable()
		{
			@Override
			public void run()
			{
				List<SpiderLogModel> list = getList("selectTaskLogBySeriesNo",
						spiderLog);
				if (list == null || list.isEmpty())
					save("insert_spider_system_log", spiderLog);
				else
					update("updateTaskLog", spiderLog);
			}
		});
	}
	
	@Override
	protected String getKey()
	{
		return "SpiderSystemMapper";
	}
	
}
